<?php
include ('chek.php');
//删除信息
if($input->get('do')=='delete'){
    $pid=$input->get('pid');
    $sql="delete from page WHERE pid='{$pid}'";
    $is=$db->query($sql);
    if($is){
        header('location:admin.php');
    }else{
        die('删除失败！');
    }
}
//获取信息总量
$number_i=$sql_result['s_page'];
$page_num=$input->get('page');
$page_num=$page_num<1?1:$page_num;
$total="select COUNT(*) as total from page";
$page_c=($page_num-1)*$number_i;

$total_num=$db->query($total)->fetch_array(MYSQLI_ASSOC)['total'];
$total_i=ceil($total_num/$number_i);

//获取信息
$sql="select * from page limit $page_c,$number_i";
$sql_result=$db->query($sql);
$rows=array();
while ($row=$sql_result->fetch_array(MYSQLI_ASSOC)){
    $rows[]=$row;
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8"/>
    <title>博客管理</title>
    <?php
    include ('../headr.php');
    ?>
</head>
<body>
<?php
include ('nav.php');
?>
<div class="container">
    <div class="row">
        <h2>博客管理<a href="admin_add.php" class="pull-right btn btn-default">添加博客</a></h2>
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>修改时间</th>
                    <th>管理</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($rows as $row) :?>
                <?php
                    $intime=date('Y-m-d H:i:s',$row['intime']) ;
                    $uptime=date('Y-m-d H:i:s',$row['uptime'])
                ?>
                <tr>
                    <td><?php echo $row['pid']?></td>
                    <td><?php echo $row['title']?></td>
                    <td><?php echo $row['aptor']?></td>
                    <td><?php echo $intime ?></td>
                    <td><?php echo $uptime?></td>
                    <td>
                        <a href="admin_add.php?pid=<?php echo $row['pid'] ?>">修改</a>
                        <a onclick="return confirm('你要确定删除吗？')" href="admin.php?do=delete&&pid=<?php echo $row['pid'] ?>">删除</a>
                    </td>
                </tr>
            <?php endforeach ;?>
            </tbody>
        </table>

        <!--  分页-->
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <?php
                $href='<li><a href="admin.php?page=%d">%s</a></li>';
                for($i=1;$i<=$total_i;$i++){
                    echo sprintf($href,$i,"第{$i}页");
                }
                ;?>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>